﻿// =================================================================== 
// 数据访问层(GDIT.DAL)
//====================================================================
// 文件：DDetailMenus.cs
// 项目名称：学院网站
// 创建时间：2012-08-08
// 负责人：ChenZhiGang
//引用DevExpress.Data.Filtering，DevExpress.Xpo程序集
// 程序集介绍：详细菜单（二级菜单）信息数据访问层
// ===================================================================
using GDIT.Model;
using DevExpress.Data.Filtering;
using DevExpress.Xpo;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GDIT.Pattern;
using System.Data;

namespace GDIT.DAL
{
    public class DDetailMenus : IDetailMenus
    {

        private XpoHelper.Test<Mtb_DetailMenus> userOperation = null;

        /// <summary>
        /// 新增二级菜单
        /// </summary>
        /// <param name="detailMenu">需要新增的二级菜单对象</param>
        /// <returns>1：新增成功 0：新增失败</returns>
        public int InsertDetailMenus(Mtb_DetailMenus detailMenu)
        {
            return XpoHelper.SaveAdded(detailMenu);
        }

        /// <summary>
        /// 删除二级菜单
        /// </summary>
        /// <param name="detailMenu">需要删除的二级菜单ID</param>
        /// <returns>1：删除成功 0：删除失败</returns>
        public int DeleteDetailMenus(int id)
        {
            userOperation = new XpoHelper.Test<Mtb_DetailMenus>();
            return userOperation.Delete(id);
        }

        /// <summary>
        /// 更新二级菜单
        /// </summary>
        /// <param name="detailMenu">需要更新的二级菜单对象</param>
        /// <returns>1：更新成功 0：更新失败</returns>
        public int UpdateDetailMenus(Mtb_DetailMenus detailMenu)
        {
            userOperation = new XpoHelper.Test<Mtb_DetailMenus>();
            XPCollection xp = userOperation.Operation("OID", detailMenu.OID);
            foreach (Mtb_DetailMenus b in xp)
            {
                b.MenuName = detailMenu.MenuName;
                b.LinkAddress = detailMenu.LinkAddress;
                return XpoHelper.SaveModified(b);
            }
            return 0;
        }

        /// <summary>
        /// 查询所有的二级菜单列表
        /// </summary>
        /// <returns>所有的二级菜单列表</returns>
        public IDataReader SelectDetailMenus()
        {
            return XpoHelper.SelectID("select OID, Main, MenuName, LinkAddress,Sn from dbo.Mtb_DetailMenus");
        }

        /// <summary>
        /// 查询单一的二级菜单对象
        /// </summary>
        /// <returns>单一的二级菜单对象</returns>
        public Mtb_DetailMenus SelectDetailMenusByDetail(Mtb_DetailMenus detailMenu)
        {
            Mtb_DetailMenus detail = null;
            userOperation = new XpoHelper.Test<Mtb_DetailMenus>();
            XPCollection xp = userOperation.Operation("OID", detailMenu.OID);
            foreach (Mtb_DetailMenus b in xp)
            {
                detail = b;
            }
            return detail;
        }
    }
}
